package com.glg.mybatis.mapper;

import com.glg.mybatis.module.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    @Select("select * from userinfo")
    List<UserInfo> getUserInfoAll();

    //带参数的查询
    @Select("select * from userinfo where id = #{id}")
    List<UserInfo> queryById(Integer id);

    //重命名参数的查询
    @Select("select * from userinfo where id = #{userid} and gender = #{gender}")
    List<UserInfo> queryByIdAndGender(@Param("userid") Integer id, Integer gender);


    //数据库的“增”操作
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo (username, password, age, gender) values (#{username}, #{password}, #{age}, #{gender})")
    Integer insert(UserInfo userInfo);

    //删除
    @Delete("delete from userinfo where id = #{id};")
    Integer delete(Integer id);

    //改
    @Update("update userinfo set password = #{password}, age = #{age}")
    Integer update(UserInfo userInfo);

    //查询
    @Select("select id, username, password, age, gender, phone, delete_flag, create_time, update_time from userinfo")
    List<UserInfo> queryAllUser();
}
